package com.wly
{
	import com.wly.datapool.DataPool;
	import com.wly.datapool.define.GlobalDefine;
	import com.wly.datapool.global.GlobalInfo;
	import com.wly.datapool.map.MapPool;
	import com.wly.datapool.stage.GameStageInfo;
	import com.wly.datapool.stage.GameStagePool;
	import com.wly.datapool.tower.TowerPool;
	import com.wly.dynamicc.DynamicManager;
	import com.wly.dynamicc.DynamicTest;
	import com.wly.ui.BGLayer;
	import com.wly.ui.sound.SoundLayer;
	
	import flash.display.MovieClip;
	import flash.events.Event;
	
	public class TDMain extends MovieClip
	{
		private var _bg:BGLayer;
		
		public function TDMain()
		{
			super();
			init();
		}
		
		private function init():void
		{
			
			var dp:DataPool = new DataPool;
			var dynamicMgr:DynamicManager = new DynamicManager;
			stage.addEventListener(Event.ENTER_FRAME, dynamicMgr.onFrame);
			
			GlobalInfo.selectTowerIndex = 0;
			_bg = new BGLayer;
			addChild(_bg);
			
			var soundLayer:SoundLayer = new SoundLayer;
			
			var activeMgr:ActiveManager = new ActiveManager;
			addChild(activeMgr.activeLayer);
			
			var panelMgr:PanelManager = new PanelManager();
			panelMgr.showGlobalInfo();
			addChild(panelMgr);
			doGameStage(GameStagePool.getInstance().getGamestageByIndex(0));
		//	_bg.updateMap(MapPool.getInstance().getMapByMapIndex(0));
		}
		
		public function doGameStage(gameStage:GameStageInfo):void
		{
			_bg.reset();
			if(gameStage)
			{
				GlobalInfo.money = GlobalDefine.STAGE_INIT_MONEY;
				_bg.updateMap(MapPool.getInstance().getMapByMapIndex(gameStage.mapIndex));
				gameStage.start();
			}
		}
	}
}